package d0318;

public class EntranceThread implements Runnable
{
    private int  number=0;
    public synchronized int setnumber()
    {
        this.number++;
        return number;
    }
    public void run()
    {
        while (true)
        {
            if (number < 30)
            {
                System.out.println(setnumber()+ "号员工从" + Thread.currentThread().getName() + "进入抽奖号码为" + (int) (100 * Math.random()));
                try
                {
                    Thread.sleep(300);
                } catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
            }
            else
            {
                System.exit(0);
            }
        }
    }
    public static void main(String[] args) {
        EntranceThread t = new EntranceThread();
        Thread t1 = new Thread(t,"前门");
        Thread t2 = new Thread(t,"后门");
        t1.start();
        t2.start();
    }
}
